from manim import *



class math1(MovingCameraScene):
    def construct(self):
        self.camera.background_color = BLACK  # 设置背景颜色
        self.camera.frame_width = 100  # 设置边框宽度
        self.camera.frame_height = 60  # 设置边框高度
        self.camera.pixel_height = 1080  # 设置像素高度
        self.camera.pixel_width = 1920  # 设置像素宽度
        self.camera.center = ORIGIN  # 设置中心点位置
        self.camera.scale_factor = 1.0  # 设置缩放因子
        #设置横线
        for i in range(6*2+1):       
            dot1=Dot([-50,5*(i-6),0]).set_opacity(0.5)
            dot2=Dot([50,5*(i-6),0]).set_opacity(0.5)
            if i==6:
                line1=Line(dot1,dot2).set_color(WHITE).set_opacity(0.5)
                
            else:
                line1=Line(dot1,dot2).set_color(WHITE).set_opacity(0.5)
               
            self.add(dot1,dot2,line1)
        #设置竖线
        for i in range(10*2+1):        
            dot3=Dot([(i-10)*5,-30,0]).set_opacity(0.5)
            dot4=Dot([(i-10)*5,30,0]).set_opacity(0.5)
            if i==10:
                line2=Line(dot3,dot4).set_color(WHITE).set_opacity(0.5)
                
            else:
                line2=Line(dot3,dot4).set_color(WHITE).set_opacity(0.5)
            self.add(dot3,dot4,line2)
        #设置三个点
        circle1 = Circle(radius=1, color=RED,fill_opacity=0.5)  
        circle1.move_to([-47.5,27.5,0]) 
        circle2 = Circle(radius=1, color=YELLOW,fill_opacity=0.5)  
        circle2.move_to([-42.5,27.5,0])  
        circle3 = Circle(radius=1, color=GREEN,fill_opacity=0.5) 
        circle3.move_to([-37.5,27.5,0])
        #镜头跟进效果
        self.camera.frame.save_state()
         #分析文本
        text100=MarkupText("<b><i>分析/解：</i></b>",color=PINK).scale(5.0).move_to([-35,7.5,0])
        self.play(Write(text100))
        #题目出现
        text = Tex(r"$ \int _{0}^{a}\sqrt{2y^{2}+a^{2}}dy$"
                   ,tex_template=TexTemplateLibrary.ctex).scale(5.0).move_to([0,20,0])
        self.play(Write(text),self.camera.frame.animate.scale(0.8).move_to([0,20,0]))

        #箭头引出
        arrow = Arrow(start=[11,25,0],end=[6,23,0], color=RED
                       , stroke_width=20, tip_length=1)
        self.play(Create(arrow))
        #文本
        long_text=("特征识别:\n"
                     "三角换元")
        text1 = Text(long_text,color=YELLOW,
                   font_size=200).move_to([20,25,0])
        #框框标
        rectangle=Rectangle(color=BLUE,fill_opacity=0.0,width=12,height=5
                            ,stroke_color=BLUE,stroke_width=20)
        rectangle.move_to([0, 20, 0])
        self.play(Create(rectangle),Create(text1))
        self.wait()

         #箭头引出
        arrow2 = Arrow(start=[0,15,0],end=[0,7,0], color=RED
                       , stroke_width=20, tip_length=1)
        self.play(Create(arrow2))
        #文本
        text2 = Tex(r"$\sqrt{2}y=a\tan t$"
                    ,color=GREEN
                   ,tex_template=TexTemplateLibrary.ctex).scale(5.0).move_to([-15,11,0])
        self.play(Write(text2))

         #文本
        text3 = Tex(r"$\dfrac{a^{2}}{\sqrt{2}}\int _{0}^{\arctan \sqrt{2}}\sec ^{3}tdt$"
                   ,tex_template=TexTemplateLibrary.ctex).scale(5.0).move_to([0,3,0])
        self.play(Write(text3),self.camera.frame.animate.move_to([0,3,0]))
        self.wait(0.5)

         #框框标记
        rectangle1=Rectangle(color=BLUE,fill_opacity=0.0,width=23,height=7
                            ,stroke_color=BLUE,stroke_width=20)
        rectangle1.move_to([0, 3, 0])
        self.play(Create(rectangle1))

        #箭头引出
        arrow3 = Arrow(start=[0,0,0],end=[0,-10,0], color=RED
                       , stroke_width=20, tip_length=1)
        self.play(Create(arrow3),self.camera.frame.animate.move_to([0,-10,0]))
        #文本
        text4 = Tex(r"$\int ^{b}_{a}f\left( x\right) dx= F\left( b\right) -F\left( a\right) $"
                    ,color=GREEN
                   ,tex_template=TexTemplateLibrary.ctex).scale(5.0).move_to([-20,-5,0])
        text5 = Tex(r"$\int \sec ^{3}tdt$"
                   ,tex_template=TexTemplateLibrary.ctex).scale(5.0).move_to([0,-12,0])
        self.play(Write(text4),Write(text5))
        
        text6 = Tex(r"$=\left( \sec t\tan t+\ln \left| \sec t+\tan t\right| \right) +c$"
                   ,tex_template=TexTemplateLibrary.ctex).scale(5.0).move_to([0,-17,0])
        self.play(Write(text6))

         












        self.play(Restore(self.camera.frame))

        self.play(FadeIn(circle1),run_time=0.1)
        self.play(FadeIn(circle2),run_time=0.1)
        self.play(FadeIn(circle3),run_time=0.1)

        self.wait()